Class Track
- java.lang.Object
-
- MusicLandscape.entities.Track
-
- All Implemented Interfaces:
ConsoleScanable
public class Track extends java.lang.Object implements ConsoleScanable
represents a piece of music that has been released on some kind of media (CD, vinyl, video, ...)- Since:
- ExerciseSheet01
- Version:
- 4
- Author:
- Jonas Altrock (ew20b126@technikum-wien.at)
-
-
Field Summary
Fields Modifier and Type Field Description private intdurationthe duration of this track in secondsprivate Artistperformerthe artist who performs this trackprivate java.lang.Stringtitlethe title of this track.private Artistwriterthe artist who wrote this trackprivate intyearthe year in which the Track was or will be produced
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetDuration()gets the duration of this trackArtistgetPerformer()returns the performer of this trackjava.lang.StringgetString()returns a formatted String containing all information of this track.java.lang.StringgetTitle()gets the title of this track.ArtistgetWriter()returns the writer of this trackintgetYear()gets the production year of this trackprotected booleanisKnown(Artist artist)Check whether an artist is known.booleanscan()Guides the user through a process that allows scanning/modifying of this track with a text-based user interface.voidsetDuration(int duration)sets the durationvoidsetPerformer(Artist performer)sets the performer of this trackvoidsetTitle(java.lang.String title)sets the title of this track.voidsetWriter(Artist writer)sets the writer of this trackvoidsetYear(int year)sets the production year of this trackjava.lang.StringtoString()returns a String representation of this trackbooleanwriterIsKnown()this getter is used to check if the writer of this Track is known.
-
-
-
Field Detail
-
duration
private int duration
the duration of this track in secondsthe duration is a non-negative number, duration 0 (zero) represents unknown duration
-
performer
private Artist performer
the artist who performs this trackthe performer cannot be null
-
title
private java.lang.String title
the title of this track.
-
writer
private Artist writer
the artist who wrote this trackthe writer cannot be null
-
year
private int year
the year in which the Track was or will be producedvalid years are between 1900-2999
-
-
Constructor Detail
-
Track
public Track()
creates a default track.a default track has the following values:
- unknown title
- duration 0
- default writer and performer
- year 1900
-
Track
public Track(java.lang.String title)
creates a track with a certain titlethe resulting track has the specified title, all other values are default
- Parameters:
title- the title of this track
-
Track
public Track(Track other)
creates a deep copy of a Track- Parameters:
other- the track to copy
-
-
Method Detail
-
getDuration
public int getDuration()
gets the duration of this track- Returns:
- the duration
-
getPerformer
public Artist getPerformer()
returns the performer of this track- Returns:
- the performer
-
getTitle
public java.lang.String getTitle()
gets the title of this track. if the title is not known (null) "unknown title" is returned (without quotes)- Returns:
- the title
-
getWriter
public Artist getWriter()
returns the writer of this track- Returns:
- the writer
-
getYear
public int getYear()
gets the production year of this track- Returns:
- the year
-
setDuration
public void setDuration(int duration)
sets the durationa negative value is ignored, the object remains unchanged
- Parameters:
duration- the duration to set
-
setPerformer
public void setPerformer(Artist performer)
sets the performer of this tracknull arguments are ignored
- Parameters:
performer- the performer to set
-
setTitle
public void setTitle(java.lang.String title)
sets the title of this track.- Parameters:
title- the title to set
-
setWriter
public void setWriter(Artist writer)
sets the writer of this tracknull arguments are ignored
- Parameters:
writer- the writer to set
-
setYear
public void setYear(int year)
sets the production year of this trackvalid years are between 1900 and 2999
other values are ignored, the object remains unchanged
- Parameters:
year- the year to set
-
writerIsKnown
public boolean writerIsKnown()
this getter is used to check if the writer of this Track is known.- Returns:
- true if the writer of this track is known (and has a name), false otherwise.
-
isKnown
protected boolean isKnown(Artist artist)
Check whether an artist is known.- Parameters:
artist- the artist to check- Returns:
- whether the artist is known or not
-
getString
public java.lang.String getString()
returns a formatted String containing all information of this track.the String representation is (without quotes):
"title by writer performed by performer (min:sec)"
where
- title stands for the title (exactly 10 chars wide) if not set, return unknown
- writer stands for the writer name (exactly 10 chars wide, right justified)
- performer stands for the performer name (exactly 10 chars wide, right justified)
- min is the duration's amount of full minutes (at least two digits, leading zeros)
- sec is the duration's remaining amount of seconds (at least two digits, leading zeros)
- Returns:
- a String representation of this track
-
toString
public java.lang.String toString()
returns a String representation of this trackthe string representation of this track is described in getString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation
-
scan
public boolean scan()
Guides the user through a process that allows scanning/modifying of this track with a text-based user interface.This method allows modification of the following fields, in the order listed:
- title
- duration
For each modifiable field the process is the following:
- field name and current value are displayed
- new value is read and validated
if input is valid, field is set, otherwise a short message is shown and input of this field is repeated.
Old values can be kept for all fields by entering an empty string. The operation cannot be cancelled, instead the user must keep all former values by repeatedly entering empty strings.
- Specified by:
scanin interfaceConsoleScanable- Returns:
- whether this object was altered or not
-
-